<template>

<div id="UserMenu">
  <div id="homeBar">
    <mu-appbar title="玩家详情" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
    </mu-appbar>
  </div>

  <mu-list>
    <mu-list-item title=""  v-if="this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <div class="mu-item-title">在线玩家<span style="color:red">&nbsp;{{ this.onlineUser }}</span></div>
      <mu-icon value="arrow_forward"  slot="right"/>
    </mu-list-item>
    <mu-list-item title="" :to="{name: 'NewUserDetail' }" v-if="!this.isBoss">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <div class="mu-item-title">今日新增玩家<span style="color:red">&nbsp;{{ this.newUser }}</span></div>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="" :to="{name: 'UserDetail' }" v-if="!this.isBoss">
      <mu-avatar v-bind:src="this.$image.icon3" slot="leftAvatar"/>
      <div class="mu-item-title">玩家总人数<span style="color:red">&nbsp;{{ this.totalUser }}</span></div>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
  </mu-list>

</div>

</template>

<script>
  export default {
    data () {
      return {
        newUser: 0,
        totalUser: 0,
        onlineUser: 0,
        startDay: this.$time.getDateBefore(new Date(), 0),
        endDay: this.$time.getDateBefore(new Date(), 0),
        isAdmin: false,
        isBoss: false
      }
    },
    methods: {
      getNewUserNumber () {
        let that = this
        this.$axios({
          method: 'get',
          url: 'api/AgentService.getNewUserNum',
          params: {'account': sessionStorage.getItem('account'), 'startDay': this.startDay, 'endDay': this.endDay}
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.newUser = resp.data.data
          }
        })
      },
      getTotalUserNumber () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getTotalUserNumber',
          params: {'account': sessionStorage.getItem('account')}
        })
        .then(function (resp) {
          that.totalUser = resp.data.data
        })
      },
      getOnlineUserNumber () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.getOnlineUserCount',
          params: {'account': sessionStorage.getItem('account')}
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.onlineUser = resp.data.data
          }
        })
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'admin') {
        this.isAdmin = true
        this.getOnlineUserNumber()
        this.getNewUserNumber()
        this.getTotalUserNumber()
      } else {
        this.getNewUserNumber()
        this.getTotalUserNumber()
      }
    }
  }
</script>
